package org.cmind.soap.android;

import java.util.HashMap;
import java.util.Map;

class NamespaceHelper {

    private String NAMESPACE_PREFIX = "ns";
    private int count = 0;
    Map<String, String> map = new HashMap<String, String>();

    public NamespaceHelper() {

    }

    public String getPrefixForNs(String namespace) {
        if (namespace == null || "".equals(namespace)) {
            return null;
        }
        return map.get(namespace);
    }

    public String registerNewNameSpace(String namespace) {
        namespace = namespace.trim();
        if (map.keySet().contains(namespace)) {
            throw new IllegalArgumentException("Namespace already registered");
        } else {
            String prefix = NAMESPACE_PREFIX + count;
            count++;
            map.put(namespace, prefix);
            return prefix;
        }

    }

}
